Version 3.0
User's Guide

Comparison Operators

Previous | Next
Contents

All NetCloak SHOW and HIDE commands let you specify one of thirteen comparison operators, which let you specify exactly how to compare a NetCloak variable to the parameters listed in the command.

A comparison operator causes NetCloak to perform a logical test, which has either a true or false result. If the result is true, then a SHOW command causes text following it to be shown; and a HIDE command causes the text to be hidden. If the result of the test is false, then the command has no effect on the page.

The comparison operator may be omitted from the command. If it is, a default comparison operator is used which is specific to each command. The default comparison operator for each command is listed in the command's description later in this User's Guide. In all cases, the default comparison operator permits backward-compatibility with versions of NetCloak prior to 3.0.

Comparison operators fall into one of two categories: text comparisons and numeric comparisons. Be sure you know which kind of operator you are using, or you will get unexpected results in your web pages.

Text Comparisons

Text comparison operators treat the variable and the command parameters as sequences of alphabetic characters. All text comparisons are case-insensitive, which means that the capitalization of the characters is ignored. Therefore, "bob" and "BoB" are considered an exact match. The text operators, and the tests they perform, are listed below.

For the examples shown below, assume the existence of a NetCloak global variable named "Platform" with the value "Macintosh".

CONTAINS
The comparison is true if the NetCloak variable contains any of the given text parameters. For example, the following commands all will cause text to be hidden:
    <HIDE_GLOBAL Platform CONTAINS "mac">    <HIDE_GLOBAL Platform CONTAINS "into">    <HIDE_GLOBAL Platform CONTAINS "mAcInTosh">
IS (Text Equality)
The comparison is true if the NetCloak variable exactly matches any one of the given text parameters. Of the following three commands, only the last one will cause text to be hidden:
    <HIDE_GLOBAL Platform IS "mac">    <HIDE_GLOBAL Platform IS "into">    <HIDE_GLOBAL Platform IS "mAcInTosh">
IN
The comparison is true if any one of the given text parameters contains the value of the NetCloak variable. The following command would cause text to be hidden:
    <HIDE_GLOBAL Platform IN "Welcome to Macintosh.">
BEGINS (Begins With)
The comparison is true if the NetCloak variable begins with the exact same sequence of characters as any one of the text parameters, including whitespace characters (spaces, tabs, and returns). Of the following three commands, only the first one will cause text to be hidden:
    <HIDE_GLOBAL Platform BEGINS "mac">    <HIDE_GLOBAL Platform BEGINS "into">    <HIDE_GLOBAL Platform BEGINS "Macintosh  ">

The third example fails the test because the text parameter contains extra space characters.

ENDS (Ends With)
The comparison is true if the NetCloak variable ends with the exact same sequence of characters as any one of the text parameters, including whitespace characters (spaces, tabs, and returns). Of the following three commands, only the first one will cause text to be hidden:
    <HIDE_GLOBAL Platform ENDS "tosh">    <HIDE_GLOBAL Platform ENDS "into">    <HIDE_GLOBAL Platform ENDS "  Macintosh">

The third example fails the test because the text parameter contains extra space characters.

BEFORE (Alphabetically)
This operator uses the ASCII value for each character in the text to determine if the NetCloak variable would be sorted alphabetically before the text parameters. If multiple parameters are listed, this comparison returns true if the variable is alphabetically before any one of the parameters. For this reason, this operator should ordinarily be used with only a single text parameter.

Using ASCII values, whitespace characters sort before digit characters, and digit characters sort before all alphabetic characters. Also, if all characters in a short word match a longer word, the shorter word sorts before the longer word.

Note: the BEFORE operator is not a date/time comparison operator. You usually do not want to use this operator in date/time commands.

Of the following examples, only the second one will cause text to be hidden using our "Platform" global variable:

    <HIDE_GLOBAL Platform BEFORE "mac">    <HIDE_GLOBAL Platform BEFORE "windows">    <HIDE_GLOBAL Platform BEFORE "123xyz">
AFTER (Alphabetically)
This operator uses the ASCII value for each character in the text to determine if the NetCloak variable would be sorted alphabetically after the text parameters. If multiple parameters are listed, this comparison returns true if the variable is alphabetically after any one of the parameters. For this reason, this operator should ordinarily be used with only a single text parameter.

Using ASCII values, whitespace characters sort before digit characters, and digit characters sort before all alphabetic characters. Also, if all characters in a short word match a longer word, the shorter word sorts before the longer word.

Note: the AFTER operator is not a date/time comparison operator. You usually do not want to use this operator in date/time commands.

Of the following examples, only the third one will cause text to be hidden using our "Platform" global variable:

    <HIDE_GLOBAL Platform AFTER "Macintosh">    <HIDE_GLOBAL Platform AFTER "windows">    <HIDE_GLOBAL Platform AFTER "123xyz">
EXISTS
This comparison doesn't really compare the NetCloak variable to anything; it always evaluates true if the variable has been defined to have any value. In fact, if this comparison operator is used, the text parameters following it are completely ignored. This comparison operator comes in handy when you want to make sure you do not overwrite a variable's value once it has already been set, such as is often the case when setting cookie values (see the SET_COOKIE command) or global variable values. For example, if the global variable named "Platform" does not already exist, the following code sets its value; otherwise, it leaves it alone:
    <HIDE_GLOBAL Platform EXISTS>    <SET_GLOBAL Platform = "Macintosh">    <SHOW>

Numeric Comparisons

Numeric comparison operators treat the variable and the command parameters as numbers, converting text parameters to numbers as necessary. Numeric values may only contain these characters:

A variable that contains other characters will be treated as text by NetCloak, and will be converted to the number zero for a numeric comparison.

In date and time commands, the date and time parameters are converted to a single number in seconds. This allows comparisons and other operations in date commands to work just like those for plain numbers.

The numeric operators, and the tests they perform, are listed below. For the examples below, assume the existence of a counter named "Orders" with a value of 250.

== (Numeric Equality)
The comparison is true if the NetCloak variable has a value that is exactly equal to any of the listed numeric values. For example, the following command will cause text to be hidden:
    <HIDE_COUNT Orders == 50 150 250 350>
LT (Less Than)
The comparison is true if the value of the NetCloak variable is less than any of the listed numeric values. In the following examples, the third one will cause text to be hidden:
    <HIDE_COUNT Orders LT 50>    <HIDE_COUNT Orders LT 250>    <HIDE_COUNT Orders LT 500>
LT= (Less Than or Equal)
The comparison is true if the value of the NetCloak variable is less than or equal to any of the listed numeric values. In the following examples, the second and the third one will cause text to be hidden:
    <HIDE_COUNT Orders LT= 50>    <HIDE_COUNT Orders LT= 250>    <HIDE_COUNT Orders LT= 500>
GT (Greater Than)
The comparison is true if the value of the NetCloak variable is greater than any of the listed numeric values. In the following examples, the first one will cause text to be hidden:
    <HIDE_COUNT Orders GT 50>    <HIDE_COUNT Orders GT 250>    <HIDE_COUNT Orders GT 500>
GT= (Greater Than or Equal)
The comparison is true if the value of the NetCloak variable is greater than or equal to any of the listed numeric values. In the following examples, the first one and the second one will cause text to be hidden:
    <HIDE_COUNT Orders GT= 50>    <HIDE_COUNT Orders GT= 250>    <HIDE_COUNT Orders GT= 500>

Negating a Comparison Operator

Comparison operators in NetCloak SHOW and HIDE commands can be negated by inserting a "#" character in the command immediately before or after the comparison operator. This character reverses the result of the comparison, so that the HIDE or SHOW occurs if the test is NOT true. Some examples will make this clear.

    <HIDE_CLIENT #CONTAINS "AOL">    Welcome America Online users!
    <SHOW>

This command shows a special message only to America Online users by hiding the text if the client name does not contain the text "AOL". Read the command like this: "Hide if the client does NOT contain AOL".

You can put the # character either at the end of the show or hide command, or either before or after the comparison operator. All of the commands below are equivalent:

    <HIDE_CLIENT#  CONTAINS "Mozilla">    <HIDE_CLIENT  #CONTAINS "Mozilla">    <HIDE_CLIENT  CONTAINS# "Mozilla">

Here is one more example:

    <HIDE_VARIABLE OSPreference IS# "MacOS">    You have selected MacOS as your preferred operating system. Congratulations!
    <SHOW>

This code hides the congratulatory message from users who have chosen some other OS. (The command reads "Hide if the form variable "OSPreference" is not "MacOS".)

The negation operator can also be used with the default comparison by adding it directly to a HIDE or SHOW command. For example:

    <HIDE><SHOW_DAY# SAT SUN>


Copyright © 1996-1999 Maxum Development Corporation

http://www.maxum.com/
Previous | Next
Contents